import axios from 'axios';

export const loadGeojson = (filepath, dataType) =>
  new Promise((resolve, reject) => {
    axios
      .get(filepath, {
        responseType: 'json',
      })
      .then((response) => {
        const res = response.data;
        if (dataType) {
          resolve(res[dataType]);
        } else {
          resolve(res.features);
        }
      })
      .catch((err) => {
        console.error(err);
        reject(err);
      });
  });
